<!DOCTYPE html>
<html>

<head>
    <title>发帖子</title>
    <meta charset="utf-8">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            margin: 0;
            padding: 0;
        }

        h1 {
            text-align: center;
            padding-top: 20px;
            color: #333;
        }

        form {
            width: 50%;
            margin: auto;
            background-color: #fff;
            border-radius: 5px;
            padding: 20px;
        }

        label {
            display: block;
            font-size: 18px;
            font-weight: bold;
            color: #555;
            margin-bottom: 10px;
        }

        input[type="text"],
        textarea {
            display: block;
            width: 100%;
            padding: 10px;
            border-radius: 5px;
            border: none;
            margin-bottom: 20px;
            box-sizing: border-box;
            font-size: 16px;
            background-color: #fff;
            border: 1px solid #ccc;
            transition: border-color .3s ease-in-out;
        }

        input[type="text"]:focus,
        textarea:focus {
            outline: none;
            border-color: #00BFFF;
        }

        input[type="submit"] {
            background-color: #4CAF50;
            color: #fff;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            display: block;
            margin: auto;
        }

        input[type="submit"]:hover {
            background-color: #3e8e41;
        }
    </style>
</head>

<body>
    <h1>自由阐述你的观点、分享你的经历</h1>
    <form id="post-article-form">
        <label for="title">标题:</label>
        <input type="text" id="title" name="title">

        <label for="author">作者:</label>
        <input type="text" id="author" name="author">

        <label for="content">内容:</label><br>
        <textarea id="content" name="content" rows="10" cols="50"></textarea>

        <input type="submit" value="发布">
    </form>
    <!DOCTYPE html>
    <html>

    <head>
        <title>发帖子</title>
        <meta charset="utf-8">
        <style>
            body {
                font-family: Arial, sans-serif;
                background-color: #f0f0f0;
                margin: 0;
                padding: 0;
            }

            h1 {
                text-align: center;
                padding-top: 20px;
                color: #333;
            }

            form {
                width: 50%;
                margin: auto;
                background-color: #fff;
                border-radius: 5px;
                padding: 20px;
            }

            label {
                display: block;
                font-size: 18px;
                font-weight: bold;
                color: #555;
                margin-bottom: 10px;
            }

            input[type="text"],
            textarea {
                display: block;
                width: 100%;
                padding: 10px;
                border-radius: 5px;
                border: none;
                margin-bottom: 20px;
                box-sizing: border-box;
                font-size: 16px;
                background-color: #fff;
                border: 1px solid #ccc;
                transition: border-color .3s ease-in-out;
            }

            input[type="text"]:focus,
            textarea:focus {
                outline: none;
                border-color: #00BFFF;
            }

            input[type="submit"] {
                background-color: #4CAF50;
                color: #fff;
                border: none;
                padding: 10px 20px;
                border-radius: 5px;
                cursor: pointer;
                display: block;
                margin: auto;
            }

            input[type="submit"]:hover {
                background-color: #3e8e41;
            }
        </style>
    </head>

    <script>
        const form = document.querySelector('#post-article-form');
        form.addEventListener('submit', async (event) => {
            event.preventDefault();
            const formData = new FormData(form);
            const jsonData = JSON.stringify(Object.fromEntries(formData));
            const response = await fetch('/post-article', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json;charset=utf8'
                },
                body: jsonData
            });
            const result = await response.json();
            if (result.status === 'success') {
                window.location.href = '/discussion';
            } else {
                alert(result.err_information);
            }
        });
    </script>

</body>

</html>
